package com.example.loginstructuredemo.login;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.loginstructuredemo.R;
import com.example.loginstructuredemo.entity.bean.ArtUserBo;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class LoginActivity extends AppCompatActivity implements ILoginView {

	@Bind(R.id.email)
	AutoCompleteTextView email;
	@Bind(R.id.password)
	EditText password;
	@Bind(R.id.email_sign_in_button)
	Button emailSignInButton;

	private final int QUEST_LOGIN = 1;

	LoginActionPresenter loginActionPresenter = new LoginActionPresenter(this);

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login1);
		ButterKnife.bind(this);
	}

//	@Override
//	public void toMainActivity(ArtUserBo artUserBo) {
//		Intent intent = new Intent(this,ShowActivity.class);
//		intent.putExtra("test",artUserBo);
//		intent.putExtra("obj",artUserBo.getName());
//		startActivity(intent);
//	}

	@OnClick(R.id.email_sign_in_button)
	public void onClick() {
		loginActionPresenter.login(email.getText().toString(),password.getText().toString(),QUEST_LOGIN);
	}

	@Override
	public void toast(String msg, int requestTag) {

	}

	@Override
	public void showProgress(int requestTag) {

	}

	@Override
	public void hideProgress(int requestTag) {

	}

	@Override
	public void loadDataSuccess(Object data, int requestTag) {
		Intent intent = new Intent(this,ShowActivity.class);
		intent.putExtra("obj",(ArtUserBo)data);
		startActivity(intent);
	}

	@Override
	public void loadDataError(Throwable e, int requestTag) {
		Toast.makeText(this, "登录请求失败 = "+e.getMessage(), Toast.LENGTH_SHORT).show();
	}

	@Override
	public String getUserName() {
		return null;
	}

	@Override
	public String getPassword() {
		return null;
	}

}
